/**
 * @author yaron
 */

/**
* String format, used like function MessageFormat.format() in java
* e.g.
* 'This is a {0} not a {1}.'.format('string', 'num') // This is a string not a num.
* 'This is a {0}, not a {1}. so parse to {2} first.'.format('string', 'num', 'num') // This is a string not a num. so parse to num first.
* 'This is a {0}, not a {1}. so parse to {1} first.'.format('string', 'num') // This is a string not a num. so parse to num first.
* 'This is a {0}, not a {1}. so parse to {2} first.'.format('string', 'num') // This is a string not a num. so parse to {2} first.
*/
String.prototype.format = function() {
	var args = arguments;
	return this.replace(/\{(\d+)\}/g, function(){
		var val = args[arguments[1]];
		return (! val) ? arguments[0] : val;
	});
};


function updateTips( t ) {
	tips
		.text( t )
		.addClass( "ui-state-highlight" );
	setTimeout(function() {
		tips.removeClass( "ui-state-highlight", 1500 );
	}, 500 );
}


function checkLength( o, n, min, max ) {
	if ( o.val().length > max || o.val().length < min ) {
		o.addClass( "ui-state-error" );
		updateTips( "字段 " + n + " 必须填写，" +
			min + " 到 " + max + "个字符." );
		return false;
	} else {
		return true;
	}
}